"""
鼠标事件及鼠标事件的处理
"""
import pygame

# 需要监听鼠标点击事件的对象的字典集合
obj_dict_listen_mousedown = dict()
# 需要监听鼠标悬浮事件的对象的字典集合
obj_dict_listen_mousemotion = dict()


def mousedown_handler(event):
    """
    鼠标点击事件处理函数
    :param event: 事件对象
    :return:
    """
    # 不为鼠标点击事件直接退出
    if event.type != pygame.MOUSEBUTTONDOWN:
        return
    # 备份一个临时字典
    obj_dict_listen_mousedown_backup = dict(obj_dict_listen_mousedown)
    # 判断是对哪个对象的点击
    for key in obj_dict_listen_mousedown_backup.keys():
        val = obj_dict_listen_mousedown_backup[key]
        if key.get_rect().collidepoint(event.pos):
            val(key, event)


def mousemotion_handler(event):
    """
    鼠标悬浮事件处理函数
    :param event: 事件对象
    :return:
    """
    # 不为鼠标悬浮事件直接退出
    if event.type != pygame.MOUSEMOTION:
        return
    # 备份一个临时字典
    obj_dict_listen_mousemotion_backup = dict(obj_dict_listen_mousemotion)
    # 判断哪个对象鼠标悬浮
    for key in obj_dict_listen_mousemotion_backup.keys():
        val = obj_dict_listen_mousemotion_backup[key]
        val(key.get_rect().collidepoint(event.pos), key, event)


def arrow_mouse():
    """
    将鼠标的样式设置为标准箭头
    :return:
    """
    pygame.mouse.set_system_cursor(pygame.SYSTEM_CURSOR_ARROW)


def hand_mouse():
    """
    将鼠标的样式设置为手形光标
    :return:
    """
    pygame.mouse.set_system_cursor(pygame.SYSTEM_CURSOR_HAND)
